package com.Xht.www.servlet;

//后端响应查询房间信息的请求

import com.Xht.www.dao.RoomTypeInfoDAO;
import com.Xht.www.po.RoomTypeInfoPO;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/QueryRoomServlet")
public class QueryRoomServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        String merchantName = request.getParameter("merchantName");
        if (merchantName != null && !merchantName.isEmpty()) {
            RoomTypeInfoDAO dao = new RoomTypeInfoDAO();
            try {
                List<RoomTypeInfoPO> roomTypeInfoList = dao.queryRoomTypeInfoByMerchantName(merchantName);

                out.println("<table border='1'>");
                out.println("<tr><th>床型</th><th>剩余数量</th><th>关键词</th><th>价格</th><th>销量</th></tr>");
                for (RoomTypeInfoPO roomTypeInfo : roomTypeInfoList) {
                    out.println("<tr>");
                    out.println("<td>" + roomTypeInfo.getBedType() + "</td>");
                    out.println("<td>" + roomTypeInfo.getRemainingQuantity() + "</td>");
                    out.println("<td>" + roomTypeInfo.getKeywords() + "</td>");
                    out.println("<td>" + roomTypeInfo.getPrice() + "</td>");
                    out.println("<td>" + roomTypeInfo.getSalesVolume() + "</td>");
                    out.println("</tr>");
                }
                out.println("</table>");
            } catch (Exception e) {
                e.printStackTrace();
                out.println("查询出错，请稍后重试。");
            }
        } else {
            out.println("商家名称未指定。");
        }
    }
}
